]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
port shell-js to c++
authorTim Lunn <tim@feathertop.org>
Sun, 6 Oct 2013 08:21:50 +0000 (19:21 +1100)
committerTim Lunn <tim@feathertop.org>
Tue, 29 Oct 2013 20:44:34 +0000 (07:44 +1100)
https://bugzilla.gnome.org/show_bug.cgi?id=711052

configure.ac
src/Makefile.am
src/shell-js.c [deleted file]
src/shell-js.cpp [new file with mode: 0644]

index d149ff2b1fb88ffd614ab7abd773bf526c4a3440..da937cd09dd7881aecb3e459d20cf8b14f97b9e3 100644 (file)
@@ -16,6 +16,7 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 
 # Checks for programs.
 AC_PROG_CC
+AC_PROG_CXX
 
 # Initialize libtool
 LT_PREREQ([2.2.6])
index 8041052d77743073e61de16300b5e9ac25fde2cd..a9f4c6271ba1b320d8afc82fabc820033057bb03 100644 (file)
@@ -207,7 +207,7 @@ endif HAVE_MUTTER_WAYLAND
 
 libgnome_shell_js_la_SOURCES =         \
        shell-js.h                      \
-       shell-js.c                      \
+       shell-js.cpp            \
        $(NULL)
 
 libgnome_shell_js_la_LIBADD =          \
diff --git a/src/shell-js.c b/src/shell-js.c
deleted file mode 100644 (file)
index 149dcd0..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-
-#include "config.h"
-
-#include "shell-js.h"
-
-#include <jsapi.h>
-#include <gio/gio.h>
-#include <gjs/gjs.h>
-#include <gjs/gjs-module.h>
-
-/**
- * shell_js_add_extension_importer:
- * @target_object_script: JavaScript code evaluating to a target object
- * @target_property: Name of property to use for importer
- * @directory: Source directory:
- * @error: A #GError
- *
- * This function sets a property named @target_property on the object
- * resulting from the evaluation of @target_object_script code, which
- * acts as a GJS importer for directory @directory.
- *
- * Returns: %TRUE on success
- */
-gboolean
-shell_js_add_extension_importer (const char  *target_object_script,
-                                 const char  *target_property,
-                                 const char  *directory,
-                                 GError     **error)
-{
-  jsval target_object;
-  GList *contexts;
-  JSContext *context;
-  char *search_path[2] = { 0, 0 };
-  gboolean ret = FALSE;
-
-  /* Take the first GjsContext from all of them --
-   * we should only ever have one context, so this
-   * should be alright. */
-  contexts = gjs_context_get_all ();
-  context = gjs_context_get_native_context (contexts->data);
-  g_list_free_full (contexts, g_object_unref);
-
-  JS_BeginRequest (context);
-
-  /* This is a bit of a hack; ideally we'd be able to pass our target
-   * object directly into this function, but introspection doesn't
-   * support that at the moment.  Instead evaluate a string to get it. */
-  if (!JS_EvaluateScript(context,
-                         JS_GetGlobalObject(context),
-                         target_object_script,
-                         strlen (target_object_script),
-                         "<target_object_script>",
-                         0,
-                         &target_object))
-    {
-      gjs_log_exception(context);
-      g_set_error(error,
-                  G_IO_ERROR,
-                  G_IO_ERROR_FAILED,
-                  "Unable to import %s", target_object_script);
-      goto out;
-    }
-
-  if (!JSVAL_IS_OBJECT (target_object))
-    {
-      g_error ("shell_js_add_extension_importer: invalid target object");
-      goto out;
-    }
-
-  search_path[0] = (char*)directory;
-  gjs_define_importer (context, JSVAL_TO_OBJECT (target_object), target_property, (const char **)search_path, FALSE);
-  ret = TRUE;
-
- out:
-  JS_EndRequest (context);
-  return ret;
-}
diff --git a/src/shell-js.cpp b/src/shell-js.cpp
new file mode 100644 (file)
index 0000000..7d057c9
--- /dev/null
@@ -0,0 +1,78 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+#include "config.h"
+
+#include "shell-js.h"
+
+#include <jsapi.h>
+#include <gio/gio.h>
+#include <gjs/gjs.h>
+#include <gjs/gjs-module.h>
+
+/**
+ * shell_js_add_extension_importer:
+ * @target_object_script: JavaScript code evaluating to a target object
+ * @target_property: Name of property to use for importer
+ * @directory: Source directory:
+ * @error: A #GError
+ *
+ * This function sets a property named @target_property on the object
+ * resulting from the evaluation of @target_object_script code, which
+ * acts as a GJS importer for directory @directory.
+ *
+ * Returns: %TRUE on success
+ */
+gboolean
+shell_js_add_extension_importer (const char  *target_object_script,
+                                 const char  *target_property,
+                                 const char  *directory,
+                                 GError     **error)
+{
+  jsval target_object;
+  GList *contexts;
+  JSContext *context;
+  char *search_path[2] = { 0, 0 };
+  gboolean ret = FALSE;
+
+  /* Take the first GjsContext from all of them --
+   * we should only ever have one context, so this
+   * should be alright. */
+  contexts = gjs_context_get_all ();
+  context = (JSContext*) gjs_context_get_native_context ((GjsContext*)contexts->data);
+  g_list_free_full (contexts, g_object_unref);
+
+  JS_BeginRequest (context);
+
+  /* This is a bit of a hack; ideally we'd be able to pass our target
+   * object directly into this function, but introspection doesn't
+   * support that at the moment.  Instead evaluate a string to get it. */
+  if (!JS_EvaluateScript(context,
+                         JS_GetGlobalObject(context),
+                         target_object_script,
+                         strlen (target_object_script),
+                         "<target_object_script>",
+                         0,
+                         &target_object))
+    {
+      gjs_log_exception(context);
+      g_set_error(error,
+                  G_IO_ERROR,
+                  G_IO_ERROR_FAILED,
+                  "Unable to import %s", target_object_script);
+      goto out;
+    }
+
+  if (!JSVAL_IS_OBJECT (target_object))
+    {
+      g_error ("shell_js_add_extension_importer: invalid target object");
+      goto out;
+    }
+
+  search_path[0] = (char*)directory;
+  gjs_define_importer (context, JSVAL_TO_OBJECT (target_object), target_property, (const char **)search_path, FALSE);
+  ret = TRUE;
+
+ out:
+  JS_EndRequest (context);
+  return ret;
+}